package com.fms.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.fms.model.Form6Model;

public class Form6DAO {
	
	private SqlSessionFactory sqlSessionFactory; 
	
	public Form6DAO(){
		sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
	}
	

	/**
	 * Returns the list of all Form6 instances from the database.
	 * @return the list of all Form6 instances from the database.
	 */
	@SuppressWarnings("unchecked")
	public List<Form6Model> selectAll(){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			List<Form6Model> list = session.selectList("Form6.getAll");
			return list;
		} finally {
			session.close();
		}
	}

	/**
	 * Returns a Form6 instance from the database.
	 * @param id primary key value used for lookup.
	 * @return A Form6 instance with a primary key value equals to pk. null if there is no matching row.
	 */
	public Form6Model selectById(int id){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			Form6Model form6 = (Form6Model) session.selectOne("Form6.getById",id);
			return form6;
		} finally {
			session.close();
		}
	}

	/**
	 * Updates an instance of Form6 in the database.
	 * @param Form6 the instance to be updated.
	 */
	public void update(Form6Model form6){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.update("Form6.update", form6);
			session.commit();
		} finally {
			session.close();
		}
	}

	/**
	 * Insert an instance of Form6 into the database.
	 * @param Form6 the instance to be persisted.
	 */
	public void insert(Form6Model form6){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.insert("Form6.insert", form6);
			session.commit();
		} finally {
			session.close();
		}
	}

	/**
	 * Delete an instance of Form6 from the database.
	 * @param id primary key value of the instance to be deleted.
	 */
	public void delete(int id){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.delete("Form6.deleteById", id);
			session.commit();
		} finally {
			session.close();
		}
	}
}
